#include "AudioClip.h"
#include <iostream>

using namespace SolidityEngine;

AudioClip::AudioClip():
    _clip(NULL)
{

}

AudioClip::~AudioClip()
{
    if(_clip) Mix_FreeChunk(_clip);
    _clip=NULL;
}

Mix_Chunk* AudioClip::GetChunk()
{
    return _clip;
}


float AudioClip::GetClipLength()
{
    if(_clip){
        //get the sample period
        int freq=MIX_DEFAULT_FREQUENCY;

        float period = 1.0f/float(freq);

        //length of clip in bytes
        int bytes = _clip->alen;

        //length in seconds
        return period*float(bytes);
    }
    return 0.0f;
}

const Mix_Chunk* AudioClip::GetChunk() const
{
    return _clip;
}
